Skip to content

Publish to PyPI with Trusted Publishing; pin actions to SHAs - #348

Merged
cdgriffith merged 1 commit into
developfrom
ci/trusted-publishing
Nov 4, 2026
Merged

cdgriffith merged 1 commit into
developfrom
ci/trusted-publishing

Conversation

@cdgriffith

Copy link
Copy Markdown
Owner

Brings the release workflow in line with PyPI Trusted Publishing, so no PyPI password lives in GitHub. Previously, four jobs each had PYPI_USERNAME / PYPI_PASSWORD.

Changes

  • Build jobs run without secrets: the generic sdist and pure wheel, the macOS/Windows Cython wheels (3.11–3.15), and the manylinux wheels from cibuildwheel. Each one runs twine check and uploads its files as an artifact.
  • One publish job waits for every build to succeed, downloads all distributions, and uploads them with pypa/gh-action-pypi-publish from the pypi environment. Its only permission is id-token: write. A failed build can no longer leave a release half-uploaded.
  • Every action in pythonpublish.yml and tests.yml is pinned to a full commit SHA, with the release tag in a comment.
  • Default permissions: {}, checkout without persisted credentials, and job timeouts.

Before the 8.0.0 release (maintainer)

  1. On PyPI, go to python-box → Publishing → Add a trusted publisher → GitHub: owner cdgriffith, repo Box, workflow pythonpublish.yml, environment pypi.
  2. After 8.0.0 publishes successfully, delete the PYPI_USERNAME / PYPI_PASSWORD repo secrets.

Lands on develop, so it ships with the Version 8.0.0 PR (#346).

🤖 Generated with Claude Code

- All build jobs (generic sdist/wheel, macOS/Windows Cython wheels,
  manylinux cibuildwheel) run without secrets and upload artifacts
- A single publish job, gated on every build succeeding, downloads all
  distributions and uploads via PyPI Trusted Publishing (OIDC) in the
  "pypi" environment; its only permission is id-token: write
- No PYPI_USERNAME / PYPI_PASSWORD secrets are used anymore
- Pin every action in both workflows to a full commit SHA
- Default token permissions to none, checkout without persisted
  credentials, add job timeouts, twine check every build

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cdgriffith
cdgriffith merged commit 5a7ada1 into develop Nov 4, 2026
35 checks passed
@cdgriffith
cdgriffith deleted the ci/trusted-publishing branch November 4, 2026 13:14
@cdgriffith cdgriffith mentioned this pull request Nov 4, 2026
cdgriffith added a commit that referenced this pull request Nov 4, 2026
* Version fix

* Fix issue #305: Merge dotted keys when non-dotted key with same prefix follows

- Add test case for issue #305 documenting the bug
- Fix __convert_and_store to merge dict values into existing Box when:
  - box_dots is enabled
  - key already exists as a Box (created from dotted keys)
  - during initialization (__created is False)
- This ensures dotted keys like 'a.b: c' are preserved when followed by
  a non-dotted key like 'a: {d: e}' in YAML files

* Preserve the Box subclass for nested boxes after unpickling

Box.__init__ derives box_class from self.__class__, but Box.__new__ hardcoded
the base Box. Unpickling calls __new__ + __setstate__ (not __init__), so a
subclass instance ended up with box_class=Box, and nested boxes created on
access after unpickling became base Box instead of the subclass. Use cls in
__new__ to match __init__.

* fix: preserve existing keys on dotted list writes

BoxList.__setitem__ unconditionally replaced the element at the target
index with a fresh empty container before recursing, so a second dotted
write into an existing element (a[0].y after a[0].x) discarded the keys
already stored there. Only replace the element when it is not already the
right container type, matching the guard in Box.__setitem__.

* fix: case-insensitive ConfigBox key lookup for __getitem__, __contains__, __delitem__, __setitem__

ConfigBox docstring advertises "loosey goosey" case-insensitive access but
__getitem__ (dict-style), __contains__, __delitem__ and __setitem__ had
no case-insensitive support. __getattr__ only retried with lowered input,
missing MixedCase→lowercase resolution.

Add _case_insensitive_key() helper and override the four dunder methods
to resolve keys case-insensitively. __getattr__ now uses the same key-scan
fallback instead of the broken .lower() retry.

* Fix serialization of frozen_box with nested lists

frozen_box stores lists as tuples of Boxes for immutability, but
Box.to_dict() only recursed into Box and BoxList values -- not tuples --
so the nested Boxes were left unconverted. to_yaml() then failed with
RepresenterError since ruamel can't represent a Box. Recurse into tuples
in to_dict(), converting nested Box/BoxList members back to native types
while preserving the tuple. Fixes #272.

* Preserve box options in BoxList.__deepcopy__

`BoxList.__deepcopy__` built the copy as `self.__class__()` with no
`box_options`, so `copy.deepcopy()` silently dropped every option
(`frozen_box`, `box_dots`, `default_box`, `box_intact_types`, …). A frozen
BoxList became mutable (and unhashable) after a deepcopy. `BoxList.__copy__`
and `Box.__deepcopy__` both preserve options; `BoxList.__deepcopy__` was the
outlier.

Mirror `Box.__deepcopy__`: build unfrozen, register in memo before recursing
(keeps cycle-safety), populate, then re-freeze via `__init__`.

* Convert ruamel YAML scalars to builtin types on load

* Test from_yaml returns builtin float/int/bool

* Note #264 ScalarFloat fix in changelog

* Fix nested boxes losing box_dots after pickle

Pickle assigns items before __setstate__, so nested Box objects were
recreated with default options and dotted lookups failed after load.

* Add a merge option for box_merge_lists

merge_update can already combine lists with extend and unique, but there
was no way to merge lists of dictionaries the way nested dicts merge. Add
a "merge" option that walks both lists by index, recursing into dicts at
the same position so their keys combine and appending any extra incoming
items. Closes #263.

* Resolve CamelCase prefixes in dotted Box lookups

* Test CamelCase paths, defaults and exact-key precedence

* Document CamelCase path lookup fix and contributor

* Flush pending default_box parents on assignment.

default_box_create_on_get=False still needs b.foo.bar = 1 to persist.
Lookups stay ephemeral. Writes attach the pending chain.

* Protect frozen BoxLists against remaining in-place mutations

* docs: correct optional dependency installation examples

* Convert replacement values in BoxList assignments

* Fix BoxList extending itself

* Fix Box.popitem LIFO order

* fix: report malformed BoxList bracket indices

Guard unmatched index expressions in dotted reads, writes and deletes.
Add regressions for nested paths, default/frozen modes and YAML loading.

Independent review: passed (security and logic).
AI-assisted contribution prepared with Hermes DEV.

* Construct BoxList without testing the input truth value

* docs: record JSON Lines string fix

* fix: honor multiline JSON for strings

* test: cover JSON Lines string round trips

* Honor explicit pop defaults without creating missing values

* Honor explicit ensure_ascii options in JSON output

* Allow same-key updates with duplicate conversion checks

* Accept source and keyword overrides in Box.update

* Release converted attribute aliases after deleting keys

* Fix pickling of frozen BoxList instances (#344)

* Prep 7.5.0: add Python 3.15, drop 3.10

- Add Python 3.15 to test matrix, classifiers and Cython wheel builds
- Add manylinux wheels for cp314 and cp315 (cp314 was missing)
- Fix python_requires (was still >=3.9) to >=3.11
- Remove now-dead tomli python_version<3.11 requirements
- Require Cython>=3.3.0 (first release with 3.15 support)
- Bump actions/checkout, setup-python, upload-artifact to v7
- Bump version to 7.5.0

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Consolidate 7.5.0 changelog and AUTHORS for merged PRs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Fix stray changelog entry from #340

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Format merged tests with black, tidy #305 test comments

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Bump version to 8.0.0

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* Add _box_internal_attrs for internal-only attributes on Box subclasses (#269)

Also make Box.copy() and __deepcopy__ return the same class instead of
hardcoding Box; ConfigBox/SBox copy overrides are no longer needed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* Fix PR #326 edge cases: stale children, frozen boxes, pickling, dotted keys

- never overwrite a key that gained a real value after the ephemeral child was handed out
- flush only when data is actually stored, so failed writes/deletes/frozen boxes never mutate the parent
- strip the pending-parent reference from pickled state
- do not create literal dotted keys for box_dots lookups; register conversion_box alias
- Box.update also creates missing parents

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* Move package metadata to pyproject.toml (PEP 621)

setup.py is reduced to the optional Cython ext_modules; Cython is deliberately
not a build requirement so sdist installs stay pure Python. Dropped the stray
py_modules=['box'] and platforms='any' (meaningless for compiled wheels).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* Replace requirements files and black with uv dependency groups and ruff config

- [dependency-groups] test/dev in pyproject.toml (toon_format as a direct git reference), uv.lock added
- [tool.ruff] (line length 120, py311, black compatible format; E/F/W/I lint), pre-commit uses ruff-pre-commit
- coverage and cibuildwheel configuration moved into pyproject.toml
- removed .black.toml, .coveragerc and requirements*.txt, dropped the no-op cythonize pre-commit hook

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* Use uv in GitHub workflows, update README and CONTRIBUTING for uv/ruff and pyproject builds

- tests.yml/pythonpublish.yml use astral-sh/setup-uv, uv sync/build and uvx twine/cibuildwheel (same matrix, targets and secrets)
- add a ruff lint/format-check job
- document building the Cython version with --no-build-isolation now that metadata is in pyproject.toml

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* Apply ruff format/lint

Mechanical changes from ruff format and ruff check --fix (import sorting, unused imports, quote style),
plus noqa for the few intentional findings (== True assertions, one long test string).
box/__init__.py is excluded from F401/I001 via per-file-ignores because its import order matters.
config_box.pyi uses builtins.bool instead of a type-ignore that the formatter would have moved.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* Update type stubs: Self for copy/__copy__/__deepcopy__, _box_internal_attrs

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* Finalize 8.0.0 changelog with a breaking changes section

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* Add bwanshoom to AUTHORS for the #269 suggestion

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* Review fixes for CI supply chain and build config

- Use toon-format 1.2.0 from PyPI instead of an unpinned git URL (now
  hash-locked in uv.lock, and pinned for cibuildwheel/pip which read pyproject)
- Split manylinux publish into a build job (runs tests, no secrets) and an
  upload-only job, so third party test deps never run alongside PyPI creds
- Quote Cython>=3.3.0 in cibuildwheel before-build (was a shell redirect)
- Pin uvx tools (ruff 0.17.3 to match lock/pre-commit, cibuildwheel 4.3.5,
  twine 6.2.0) so CI does not drift
- Point uv at the setup-python interpreter (UV_PYTHON) in matrix jobs so each
  cell, including pypy, tests the interpreter it claims to

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Pin astral-sh/setup-uv to v10.3.3 commit (no floating v10 tag exists)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* CI: pass setup-python interpreter to uv sync/venv instead of exporting UV_PYTHON

Exporting UV_PYTHON made uv build / uv pip target the bare interpreter rather
than the project .venv, so --no-build-isolation builds could not find setuptools.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Fix #321 review issues: convert only numbers and bools, handle anchored booleans and keys

The submitted conversion turned anchored booleans (ruamel ScalarBoolean, not an int
subclass in the bool sense) into int 1, and converted ruamel string types to str,
which dropped literal block style and preserved quotes on to_yaml. Strings are now
left untouched, ScalarBoolean maps to bool, and mapping keys are converted too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Skip the PyYAML backend test when PyYAML is not installed (cibuildwheel env)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Rework #314: case-insensitive ConfigBox keys where the latest write wins

The PR as submitted crashed on non-string keys, silently merged keys that
differ only by case into the first spelling, made update and merge_update
disagree, and scanned every key on each miss.

* Only str keys are matched ignoring case, other keys match exactly
* A ConfigBox never holds two keys differing only by case: the latest write
  wins, keeping its value and its spelling (construction, [] and attribute
  assignment, update, merge_update and |)
* Lookups, in, del, pop, get and box_dots paths (first segment, nested
  ConfigBoxes match the rest) all resolve case-insensitively
* A lower-case index in the box config makes misses O(1). It is rebuilt
  when the dict size changes behind ConfigBox's back
* A stale default_box ephemeral child is not attached when the key was
  since assigned under a different spelling
* Frozen ConfigBoxes still refuse every write

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* 8.0.0 features: create_on_get off by default, subclass defaults, YAML key order, camel keep keys, int keys in dotted paths

* #262 default_box_create_on_get now defaults to False, so attribute probing
  (IPython, Spyder, hasattr) never adds keys. pop() of a missing key and
  hasattr + delattr (argparse namespaces) keep working with it.
* #296 / #223 / #210 _box_defaults class attribute: subclasses change option
  defaults without overriding __init__. Options are now read from kwargs in
  one place (_build_box_config), so an explicit option still wins. DDBox uses it.
* #104 to_yaml keeps insertion order for PyYAML and ruamel safe / unsafe too,
  sort_keys=True sorts.
* #279 camel_killer_box_keep_keys keeps CamelCase keys and adds snake_case
  attribute aliases through conversion_box.
* #123 box_dots path segments made of digits also match int keys. Only for
  path segments, a str key of the same value wins, plain keys are not mapped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Convert nested containers during BoxList in-place addition

* Publish to PyPI with Trusted Publishing and pin actions to SHAs (#348)

- All build jobs (generic sdist/wheel, macOS/Windows Cython wheels,
  manylinux cibuildwheel) run without secrets and upload artifacts
- A single publish job, gated on every build succeeding, downloads all
  distributions and uploads via PyPI Trusted Publishing (OIDC) in the
  "pypi" environment; its only permission is id-token: write
- No PYPI_USERNAME / PYPI_PASSWORD secrets are used anymore
- Pin every action in both workflows to a full commit SHA
- Default token permissions to none, checkout without persisted
  credentials, add job timeouts, twine check every build

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

* Reach 100% line and branch coverage, enforce it in CI

Tests for the remaining reachable paths (error branches, optional YAML / TOML /
TOON backends, ConfigBox index upkeep, default_box_attr call signatures, IPython
probes, reflected operators). Code that could not run was removed instead:

* _parse_box_dots error handlers at call sites that already guarantee a "." or
  "[" in the key, and its unreachable `setting` split
* the _dunder_ check in __get_default (__getattr__ refuses those names first)
  and the __getstate__ AttributeError case (Box defines __getstate__)
* tomli / toml read fallbacks (tomllib is always present on Python 3.11+) and
  try/except blocks around TOML writes that only caught decode errors
* box_from_string's BoxList fallback for TOML (a TOML document is always a table)
* DDBox.__repr__, identical to the inherited SBox one

Import time environment fallbacks and the Python 3.11 slice branch are marked
`pragma: no cover`. A new pure Python CI job fails below 100%.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Add 80 edge case tests and fix the 5 bugs they found

* `in` / get() for box_dots paths through lists ('a[0].x'), and no longer
  treating substrings of string values as keys
* IndexError on a box_dots key ending with "." with default_box
* _get_property_func assumed every class attribute was a property; the
  msgpack / toon converters are now protected keys like the others
* BoxList.__deepcopy__ of a frozen list unfroze the copied Boxes
* BoxList pickling appended items before restoring box_options, so items were
  rebuilt with default options (and unfrozen). __reduce_ex__ now keeps the
  items in the state, Box 7 pickles still load through __setstate__

A sixth finding, BoxList += not converting items, stays a strict xfail: PR #347
fixes it. The setdefault box_dots fallback is gone, `in` covers it now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Update development dependencies to their latest versions

* pyproject dependency group minimums raised to the current releases, and the
  pytest-cov<6 cap lifted (pytest-cov 7.1.0); uv.lock upgraded with uv 0.13.7
* Cython 3.3.1 for cibuildwheel and the publish workflow, twine 7.0.0
* pre-commit: pre-commit-hooks v6.0.0 (drops the removed fix-encoding-pragma
  hook), mirrors-mypy v2.4.1 with current type dependencies
* Fix the 4 errors the per-file pre-commit mypy run reports (StringIO / file
  variable type, list operator signatures, Callable in a type comment)

ruff 0.17.3 and cibuildwheel 4.3.5 were already the latest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Keep options for dict | Box and dict + Box, class factories for default_box_attr, ConfigBox "off"

* __radd__ / __ror__ build the result from a plain dict with the Box's class
  and options (unfrozen, top level namespace), like __sub__ already did
* default_box_attr: list maps to BoxList like [] does, other classes and
  functions are called like defaultdict factories. key / box_instance are
  passed by keyword (positional only parameters positionally), any other
  required parameter is an error
* ConfigBox.bool: "off" is false, as in configparser

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Add comments on Box keys and BoxList items, kept through YAML (#184)

Comments live outside the data, in a per container store
({key: {"before": [lines], "eol": text}} plus document start / end), so
to_dict, to_json, equality and hashing never see them.

* from_yaml with ruamel's round trip loader extracts them (box.comments
  re-assigns ruamel's "comment above a key" tokens, which it parses onto the
  previous key), to_yaml rebuilds CommentedMap / CommentedSeq objects and
  writes them back. Without comments, or with PyYAML / the safe dumper, the
  output is exactly as before.
* get_comment / set_comment / del_comment on Box and BoxList, positions
  "eol" / "before", key None for the document ("start" / "end"), box_dots
  paths, negative list indexes, frozen boxes refuse changes.
* Kept in sync: deletes, pop, popitem, clear drop them; ConfigBox latest
  write wins keeps the comment on the new spelling; camel_killer keys;
  BoxList insert / pop / remove / del / reverse / sort move them with their
  items (slice writes drop them); copy, deepcopy, pickle and Box(other_box)
  carry them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Comments: treat every YAML line break as a line break, reject control characters

A comment containing \r, \x85, \u2028 or \u2029 was written with that
character inside a "#" line, and YAML parsers read the rest of the line as
document content, so set_comment("a", "x\rinjected: 1") added a key on reload.
All YAML line breaks now split comment lines (end of line comments reject them)
and other control characters are refused. Found by the automated security review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Jeroen van Bemmel <jvb127@gmail.com>
Co-authored-by: kigland <shuaizhicheng336@gmail.com>
Co-authored-by: Vincent Gao <gaobing1230@gmail.com>
Co-authored-by: apoorvdarshan <ad13dtu@gmail.com>
Co-authored-by: chuenchen309 <48723787+chuenchen309@users.noreply.github.com>
Co-authored-by: tan_unique <143566827+vinson0522@users.noreply.github.com>
Co-authored-by: SeaStar Deng <37767638+DSeaStar@users.noreply.github.com>
Co-authored-by: Chris (ChrisJr404) <11917633+ChrisJr404@users.noreply.github.com>
Co-authored-by: Guo Jiarui <799423879@qq.com>
Co-authored-by: Gyanu Mayank <gyanumayank0@gmail.com>
Co-authored-by: Vitaliy <160263432+vitalivo@users.noreply.github.com>
Co-authored-by: Alex <100605452+Likio3000@users.noreply.github.com>
Co-authored-by: x0Lazarus <113273587+x0Lazarus@users.noreply.github.com>
Co-authored-by: machines-6657 <machines-6657@users.noreply.github.com>
Co-authored-by: Arindam Sikder <88596876+arindamsikder@users.noreply.github.com>
Co-authored-by: fhgffy <102001626+fhgffy@users.noreply.github.com>
Co-authored-by: shguild <shifensuperme@gmail.com>
Co-authored-by: Huanyi Xie <74809554+xiehuanyi@users.noreply.github.com>
Co-authored-by: Muneeb Sheikh <muneikh@gmail.com>
Co-authored-by: AryanRG <aryanrganjoo@gmail.com>
Co-authored-by: Gary <182863204+gary1110086@users.noreply.github.com>
Co-authored-by: Abhinav Maurya <owner@wegenz.in>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: lin <hanxianfan123@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant